﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Sector7.Framework.EntityType;
using Sector7.Framework.Core;

namespace Sector7.Framework.Services
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码和配置文件中的接口名“ICoreService”。
    /// <summary>
    /// 核心服务
    /// </summary>
    [ServiceContract]
    public interface ICoreService
    {
        #region /// System

        /// <summary>
        /// 初始化数据库
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        int InitializeDatabase();

        /// <summary>
        /// 创建数据库表
        /// </summary>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <param name="sql">建表语句</param>
        /// <returns></returns>
        [OperationContract]
        int CreateTable(string connectionString, string sql);

        /// <summary>
        /// 数据迁移
        /// </summary>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <param name="datas">将迁移的数据</param>
        /// <returns></returns>
        [OperationContract]
        int InsertDatasToTable(string connectionString, List<S7_DatabaseTable> datas);

        /// <summary>
        /// 值域映射数据元
        /// </summary>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <param name="mapping">值域映射相关的值</param>
        /// <returns></returns>
        //[OperationContract]
        //int ValueDomainMappingDataElement(string connectionString, List<M7_ValueDomainMapping> mappingValue);

        #endregion

        #region /// DataElement

        /// <summary>
        /// 添加数据元
        /// </summary>
        /// <param name="dataElement">数据元</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        object AddDataElement(S7_DataElement dataElement);

        /// <summary>
        /// 根据数据分组获取所有数据元
        /// </summary>
        /// <param name="groupId">数据分组编号</param>
        /// <returns>数据元列表</returns>
        [OperationContract]
        List<S7_DataElement> GetAllDataElementsByGroupId(int groupId);

        /// <summary>
        /// 修改数据元
        /// </summary>
        /// <param name="delta">数据元改变量</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        int SetDataElement(EntityDeltaBase delta);

        /// <summary>
        /// 删除数据元
        /// </summary>
        /// <param name="elementId">数据元编号</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        int DeleteDataElement(string elementId);

        #endregion

        #region /// ValueDomain

        /// <summary>
        /// 添加数据元值域
        /// </summary>
        /// <param name="valueDomain">数据元值域</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        object AddValueDomain(S7_ValueDomain valueDomain);

        /// <summary>
        /// 获取所有数据元值域（不包含子集）
        /// </summary>
        /// <returns>数据元值域列表</returns>
        [OperationContract]
        List<S7_ValueDomain> GetAllValueDomains();

        /// <summary>
        /// 根据数据分组编号获取所有数据元值域
        /// </summary>
        /// <param name="groupId">数据分组编号</param>
        /// <returns>数据元值域列表</returns>
        [OperationContract]
        List<S7_ValueDomain> GetAllValueDomainsByGroupId(int groupId);

        /// <summary>
        /// 更新值域
        /// </summary>
        /// <param name="delta">值域改变量</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        int SetValueDomain(EntityDeltaBase delta);

        /// <summary>
        /// 删除值域
        /// </summary>
        /// <param name="domainId">值域编号</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        int DeleteValueDomain(string domainId);

        #endregion

        #region /// ValueDomainItem

        /// <summary>
        /// 添加值域项
        /// </summary>
        /// <param name="domainItem">值域项</param>
        /// <returns>值域项编号</returns>
        [OperationContract]
        object AddValueDomainItem(S7_ValueDomainItem domainItem);

        /// <summary>
        /// 根据值域编号获取所有数据元值域项
        /// </summary>
        /// <param name="domainId">值域编号</param>
        /// <returns>值域子项列表</returns>
        [OperationContract]
        List<S7_ValueDomainItem> GetAllValueDomainItemsByDomainId(string domainId);

        /// <summary>
        /// 更新值域项
        /// </summary>
        /// <param name="delta">值域项改变量</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        int SetValueDomainItem(EntityDeltaBase delta);

        /// <summary>
        /// 删除值域项
        /// </summary>
        /// <param name="domainItemId">值域项编号</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        int DeleteValueDomainItem(object domainItemId);

        #endregion

        #region /// ValueType

        /// <summary>
        /// 添加数据元值类型
        /// </summary>
        /// <param name="valueType">数据元值类型</param>
        /// <returns>数据元值类型主键</returns>
        [OperationContract]
        object AddValueType(S7_ValueType valueType);

        /// <summary>
        /// 获取所有数据元值类型
        /// </summary>
        /// <returns>数据元值类型列表</returns>
        [OperationContract]
        List<S7_ValueType> GetAllValueTypes();

        /// <summary>
        /// 修改数据元值类型
        /// </summary>
        /// <param name="delta">数据元值类型改变量</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        int SetValueType(EntityDeltaBase delta);

        #endregion

        #region /// DataTemplate

        /// <summary>
        /// 添加数据模板
        /// </summary>
        /// <param name="dataTemplate">数据模板</param>
        /// <returns>数据模板主键</returns>
        [OperationContract]
        object AddDataTemplate(S7_DataTemplate dataTemplate);

        /// <summary>
        /// 获取所有数据模板
        /// </summary>
        /// <returns>数据模板列表</returns>
        [OperationContract]
        List<S7_DataTemplate> GetAllDataTemplates();

        /// <summary>
        /// 删除数据元模板
        /// </summary>
        /// <param name="templateId"></param>
        /// <returns></returns>
        [OperationContract]
        int DeleteDataTemplate(int templateId);
        #endregion

        #region /// DataTemplateItem

        /// <summary>
        /// 根据数据模板编号获取所有数据模板项列表
        /// </summary>
        /// <param name="templateId">数据模板编号</param>
        /// <returns>数据模板项列表</returns>
        [OperationContract]
        List<S7_DataTemplateItem> GetAllDataTemplateItemsByTemplateId(int templateId);

        #endregion

        #region /// Metadata

        /// <summary>
        /// 添加内部数据元
        /// </summary>
        /// <param name="metadata">内部数据元</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        object AddMetadata(S7_Metadata metadata);

        /// <summary>
        /// 根据数据分组获取所有内部数据元
        /// </summary>
        /// <param name="groupId">数据分组编号</param>
        /// <returns>内部数据元列表</returns>
        [OperationContract]
        List<S7_Metadata> GetAllMetadatasByGroupId(int groupId);

        [OperationContract]
        List<S7_Metadata> GetAllMetadatas();
        
        /// <summary>
        /// 修改内部数据元
        /// </summary>
        /// <param name="delta">内部数据元改变量</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        int SetMetadata(EntityDeltaBase delta);

        #endregion

        #region /// DataGroup

        /// <summary>
        /// 添加数据分组
        /// </summary>
        /// <param name="dataGroup">数据分组</param>
        /// <returns>数据分组编号</returns>
        [OperationContract]
        object AddDataGroup(S7_DataGroup dataGroup);

        /// <summary>
        /// 获取所有数据分组
        /// </summary>
        /// <returns>数据分组列表</returns>
        [OperationContract]
        List<S7_DataGroup> GetAllDataGroups();

        /// <summary>
        /// 根据类型获取所有数据分组
        /// </summary>
        /// <param name="typeId">数据分组类型</param>
        /// <returns>数据分组列表</returns>
        [OperationContract]
        List<S7_DataGroup> GetAllDataGroupsByTypeId(int typeId);

        /// <summary>
        /// 修改数据分组
        /// </summary>
        /// <param name="delta">数据分组改变量</param>
        /// <returns>操作结果</returns>
        [OperationContract]
        int SetDataGroup(EntityDeltaBase delta);

        /// <summary>
        /// 根据分组标识符获取数据分组
        /// </summary>
        /// <param name="groupIdentifier">分组标识符</param>
        /// <returns>数据分组</returns>
        [OperationContract]
        S7_DataGroup GetDataGroupByIdentifier(string groupIdentifier);

        #endregion
    }
}
